/* 
 *author Kate
 */
var currentPage;

    function doFilter(){
        getProducts(1);

    }
    
    function changePage(pageNumber){
        getProducts(pageNumber);
        
    }
   
   
    function printPages(pageNumber ){
        currentPage=pageNumber;
        var count = document.getElementById("count").value;
        var totalPages =Math.ceil(count / 10);
        if (totalPages==0 ) {totalPages=1;}
        var allPages;
        var disabled;
        
        if(pageNumber==1){
            disabled= "disabled";   
        }else{
            disabled= "";
        }
        allPages="<input class=\"navigation_btn\" \n\
                type=\"button\" \n\
                value=\"<<\"\n\
                onclick=\"changePage("+(pageNumber-1)+")\""+disabled+"/>"; 
    
        if(totalPages>6){
    
    
            //print 1 symbol
            allPages+=printPageNumber(1,pageNumber);
            //print 2 symbol
            if (pageNumber > 3) {
                allPages+=", ...";
            } else {
                allPages+=(", " + printPageNumber(2,pageNumber));
            }
            //print 3 symbol        
            if (pageNumber == 1) {
                allPages+=(", ... ");
            } else if (pageNumber < 5) {
                allPages+=(", " + printPageNumber(3,pageNumber));
            } else {
                allPages+=(", " + printPageNumber(pageNumber - 1,pageNumber));
            }
            //print 4 symbol  
            if (pageNumber == 1) {
                allPages+=(", " + printPageNumber(totalPages,pageNumber));
            } else if (pageNumber == 2) {
                allPages+=(", ... ");
            } else if (pageNumber == 3) {
                allPages+=(", " + printPageNumber(4,pageNumber));
            } else if (pageNumber == totalPages - 2) {
                allPages+=(", " + printPageNumber(totalPages - 2,pageNumber));
            } else if (pageNumber == totalPages - 1) {
                allPages+=(", " + printPageNumber(totalPages - 1,pageNumber));
            } else if (pageNumber == totalPages) {
                allPages+=(", " + printPageNumber(totalPages,pageNumber));
            } else {
                allPages+=(", " + printPageNumber(pageNumber,pageNumber));
            }

            //print 5 symbol  
            if (pageNumber == 2) {
                allPages+=(", " + printPageNumber(totalPages,pageNumber));
            } else if (pageNumber == 3) {
                allPages+=(", ... ");
            } else if (pageNumber > 3 && pageNumber < totalPages - 2) {
                allPages+=(", " + printPageNumber(pageNumber + 1,pageNumber));
            } else if (pageNumber == totalPages - 2) {
                allPages+=(", " + printPageNumber(totalPages - 1,pageNumber));
            } else if (pageNumber == totalPages - 1) {
                allPages+=(", " + printPageNumber(totalPages,pageNumber));
            }

            //print 6 symbol  
            if (pageNumber == 3 || pageNumber == totalPages - 2) {
                allPages+=(", " + printPageNumber(totalPages,pageNumber));
            } else if (pageNumber > 3 && pageNumber < totalPages - 2) {
                allPages+=(", ... ");
            }

            //print 7 symbol  
            if (pageNumber > 3 && pageNumber < totalPages - 2) {
                allPages+=(", " + printPageNumber(totalPages,pageNumber));
            }
        }else{
            for(var i=1;i<totalPages;i++ ){
                allPages+=printPageNumber(i, pageNumber)+", ";  
            }
            allPages+=printPageNumber(totalPages, pageNumber);
        
        
        }
    
        if(pageNumber==totalPages){
            disabled= "disabled";   
        }else{
            disabled= "";
        }
        allPages+="<input class=\"navigation_btn\" \n\
                type=\"button\" \n\
                value=\">>\"\n\
                onclick=\"changePage("+(pageNumber+1)+")\""+disabled+"/>"; 
   
        document.getElementById("top_pages").innerHTML=allPages;
        document.getElementById("bottom_pages").innerHTML=allPages;
    }
    
    
    function printPageNumber(pageNumber, currentPageNumber){
        var result= "<a href=# onclick=\"changePage("+pageNumber+")\"> "+pageNumber+"</a>";
        if (pageNumber== currentPageNumber){
            result="<b><a href=# style=\"color: red\" onclick=\"changePage("+pageNumber+")\"> "+pageNumber+"</a></b>";         
        }
        return result;
    }
    
 

